<!DOCTYPE html>
<html lang="en">
<head>
    <title>首次面访</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <script src="https://file.ggxqce.com/web/vue.min.js"></script>
    <script type="text/javascript"
            src="https://api.map.baidu.com/api?v=2.0&ak=18eZsB5LvSoIf1HZOCUBDXKWHMbvhfpa"></script>
    <link rel="stylesheet" href="/dist/plugins/calendar/calendar.css"/>
</head>
<style>
    [v-cloak] {
        display: none;
    }

    * {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        font-size: 12px;
    }

    body {
        margin: 1px;
        background: #ffffff;
    }

    table {
        border-spacing: 0;
        border-collapse: collapse;
        display: table;
    }

    .allmap {
        width: 100%;
        height: 300px;
        overflow: hidden;
        margin: 0;
        font-family: "微软雅黑";
    }

    .templateStyle {
        margin-top: 5px;
        margin-left: 10px;
        margin-right: 10px;
    }

    .weather {
        text-align: center;
        font-size: 16px;
        position: absolute;
        top: 5px;
        line-height: 30px;
        float: left;
    }

    .weather img {
        height: 30px;
        width: 30px;
        float: left;
    }

    .boxItem {
        width: 100%;
        margin-top: 5px;
        background: inherit;
        /*background-color: rgba(255, 255, 255, 1);*/
        border: none;
        position: relative;
    }

    .templateStyle {
        margin-top: 15px;
        margin-left: 10px;
        margin-right: 10px;
        position: relative;
    }

    .BMap_cpyCtrl {
        display: none;
    }

    .anchorBL {
        display: none;
    }

    .mapLog {
        /*background: rgb(255, 255, 255);*/
        z-index: 111111;
        overflow: hidden;
    }

    .leftLog {
        height: 16px;
        line-height: 16px;
        float: right;
    }

    .leftLog i {
        width: 8px;
        height: 8px;
        background: #1626ff;
        float: left;
        border-radius: 50%;
        margin: 4px 2px 0px;
    }

    .rightLog {
        height: 16px;
        line-height: 16px;
        float: right;

    }

    .rightLog i {
        width: 8px;
        height: 8px;
        background: red;
        float: left;
        border-radius: 50%;
        margin: 4px 2px 0px;
    }

    .ht-rili-leftarr, .ht-rili-rightarr {
        display: none;
    }

    .tryStyles {
        width: 50px;
        height: 25px;
        line-height: 25px;
        font-size: 12px;
        top: -2px;
        left: 100px;
        position: absolute;
        border-radius: 50px;
        margin-top: 4px;
        background: #ff131c;
        color: #fff;
        margin-right: -2px;
        transform: scale(0.5);
        text-align: center;
    }

    .tryStyles1 {
        width: 50px;
        height: 25px;
        line-height: 25px;
        font-size: 12px;
        top: 16px;
        left: 100px;
        position: absolute;
        border-radius: 50px;
        margin-top: 4px;
        background: #ff131c;
        color: #fff;
        margin-right: -2px;
        transform: scale(0.5);
        text-align: center;
    }
</style>
<body>

<section class="content" id="app" v-cloak>
    <div class="div-td-content-more"><i></i></div>
    <!--<div class="template" style="margin-top: 5px;margin-left: 10px;margin-right: 10px;">-->
    <!--<table class="table table-bordered text-center table-width" style="width: 100%;">-->
    <!--<tbody>-->
    <!--<tr>-->
    <!--<td style="background: #2a8cec;color: #fff;text-align: center;">兰州大区</td>-->
    <!--</tr>-->
    <!--</tbody>-->
    <!--</table>-->
    <!--</div>-->
    <div
            v-for="(allPlanItem,p) in allPlanList"
            v-if="allPlanItem.planList&&allPlanItem.planList.length>0">
        <!--<table class="table table-bordered text-center table-width" style="width: 100%;">-->
        <!--<tbody>-->
        <!--<tr>-->
        <!--<td colspan="4" style="background: #2a8cec;color: #fff;text-align: center;">-->
        <!--{{allPlanItem.title}}-->
        <!--</td>-->
        <!--</tr>-->
        <!--</tbody>-->
        <!--</table>-->
        <!--<div style="height:26px;line-height:26px;background: #2a8cec;color: #fff;text-align: center;margin-top: 15px;margin-left: 10px;margin-right: 10px;margin-bottom: -15px;box-shadow: 2px 0px 2px #DDDDDD;">-->
        <!--{{allPlanItem.title}}-->
        <!--</div>-->

        <div v-for="(item,i) in allPlanItem.planList">
            <div class="templateStyle">
                <!--天气-->
                <div style="position:relative;height: 28px;border: 1px solid #cbcbcd;background-color: #fff">
                    <div class="weather" v-if="item.weather&&item.weather.text_day"
                         style="position:absolute;top: -2px;left:0px;">
                        <b style="margin: 0 2px;">{{item.weather.text_day}}</b><font
                            class="blue">{{item.weather.low}}</font>～<font
                            class="red">{{item.weather.high}}℃</font><img
                            :src="'/dist/img/weather/'+item.weather.code_day+'.png'"/></div>
                    <div style="display:block;text-align: center;margin-top: 4px">
                        <!--item.userName.length<3?item.userName.substring(0,1)+'&nbsp;&nbsp;&nbsp;&nbsp;'+item.userName.substring(1,2):item.userName-->
                        <span v-if="item.roleName == '区域总监' || item.roleName == '销售总监'">
                             {{item.userName}}({{item.roleName}})
                        </span>
                        <span v-else>
                            {{item.userName}}({{item.departName.replace('大区','')}})
                        </span>

                    </div>
                    <template v-if="item.roleName == '区域总监' || item.roleName == '销售总监'"></template>
                    <template v-else>
                        <div style="position:absolute;top: 0;right:0;bottom: 0;font-size: 12px;background: #2c8cec;color: #fff;padding: 3px 6px">
                    <span @click="lookDaQu(item)">
                        查看下属
                    </span>
                        </div>
                    </template>
                </div>
                <template v-if="item.signInLatitude">
                    <div class="allmap" :id="'map'+p+'-'+i" v-line-inserted="p+'-'+i"
                         style="border: 1px solid #cbcbcd;"></div>
                    <div style="padding: 5px 10px;border:  1px solid #cbcbcd;margin-top: -1px;position:relative;">
                        <div class="mapLog" v-if="item.signTime||item.arrivalsTime">
                            <div style="position: absolute;right: 13px;">
                                <div>
                                <span v-if="item.signTime" class="leftLog"
                                      style="float: left;margin-top: 2px;">
                                    <!--<i  style="background: #1626ff;"></i>-->
                                    今日考勤签到：{{new Date(item.signTime).Format("hh:mm")}}</span><br>
                                    <span v-if="item.signTime" class="leftLog"
                                          style="float: left;margin-top: 4px;">
                                    <!--<i  style="background: red;"></i>-->
                                    首次面访签到：{{item.arrivalsTime? new Date(item.arrivalsTime).Format("hh:mm") : '&nbsp;--&nbsp;:&nbsp;--'}}</span>
                                </div>
                            </div>
                            间隔：
                            <span style="margin-right: 10px;" v-if="item.signInDiff != ''">
                                <span v-if="!timeJq(item.signInDiff)" style="color:red">
                                    {{addZeroHour(quMiao(item.signInDiff))?addZeroHour(quMiao(item.signInDiff)):'--'}}
                                </span>
                                <span v-else>
                                    {{addZeroHour(quMiao(item.signInDiff))?addZeroHour(quMiao(item.signInDiff)):'--'}}
                                </span>
                                <!--<template>-->
                                <!--<span class="tryStyles" v-if="!timeJq(item.signInDiff)">不合理</span>-->
                                <!--</template>-->
                            </span>
                            <span v-else>--</span>
                            <br>
                            距离：
                            <span style="margin-right: 10px;" v-if="item.signInDiff != ''">
                                <span v-if="dJq(item.signInDistance)>15" style="color:red">
                                {{dJq(item.signInDistance)?dJq(item.signInDistance)+'公里':'--'}}
                                    </span>
                                <span v-else>
                                       {{dJq(item.signInDistance)?dJq(item.signInDistance)+'公里':'--'}}
                                </span>
                                <!--<template>-->
                                <!--<span class="tryStyles1"-->
                                <!--v-if="dJq(item.signInDistance)>15">不合理</span>-->
                                <!--</template>-->
                            </span>
                            <span v-else>--</span>
                            <br>
                            时速：<span style="padding-left: 3px;" v-if="item.signInspeed != ''">{{item.signInspeed?item.signInspeed:'--'}}</span>
                            <span v-else style="padding-left: 3px;">--</span>
                        </div>

                    </div>
                </template>
                <template v-else>
                    <!--<template v-if="item.arrivalsLatitude==1">-->
                    <!--<div style="height: 70px;line-height: 70px;text-align: center;background: #ffffff;border: 1px solid #cbcbcd;margin-top: -1px;">-->
                    <!--<b style="color: #999999;">暂无首次面访</b>-->
                    <!--</div>-->
                    <!--</template>-->
                    <template
                            v-if="item.leave && item.leave.beginTime && item.leave.beginTime.length > 2">
                        <!--请假-->
                        <!--id="demo-box"-->
                        <div class="calendar-box demo-box" :id="'demo-box'+p+'-'+i"
                             v-line-inserted2="p+'-'+i"></div>
                        <div style="padding:5px 10px;    border: 1px solid rgb(203, 203, 205);">
                            <div style="display: flex">
                                <span> 请假原因：</span>
                                <span style="flex: 1" class="qjyy">{{item.leave.remark}}</span>
                            </div>
                        </div>
                        <!--</div>-->
                    </template>
                    <template v-else>
                        <!--缺勤-->
                        <div v-if="returnFlag">
                            <div style="text-align: center;background: #ffffff;padding: 30px;border: 1px solid #cbcbcd;border-top: 0px;">
                                <div style="text-align: center"><img width="45%"
                                                                     src="/dist/img/icon_seal_queqin.png"/>
                                </div>
                            </div>
                        </div>
                    </template>
                </template>
            </div>
        </div>
    </div>
    <div style="margin-bottom: 15px;"></div>


</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="/dist/plugins/scroll/myScroll.js"></script>
<!--框架已定义 JS-->
<!--oa自定义  JS-->
<script src="/dist/js/oaApp.js"></script>

<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script src="/dist/plugins/calendar/calendar-pro.js"></script>
<script type="text/javascript">
    //
</script>
<script>
    $(function () {
        $("body").on("click", ".lineOne,.lineTwo", function (e) {
            if ($(".div-td-content-more").is(":hidden")) {
                var text = $(this).text();
                if (text != "") {
                    text = "<i></i>" + text;
                    $(".div-td-content-more").html(text).css({
                        "width": $(this).outerWidth() + "px",
                        "left": $(this).offset().left,
                        "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                    }).show();
                    e.stopPropagation();
                }
            } else {
                $(".div-td-content-more").hide();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });
</script>
<script>
    $.ajaxSetup({
        global: true,
        type: "POST",
        cache: false,
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        beforeSend: function () {
        },
        complete: function () {

        },
        error: function (e) {
            alert('error' + e.responseText);
        }
    });
    $.extend($.wyui, {
        postMethod: function (url, data, callback, sync, id) {
            if (!id) {
                id = "#app"
            }
            $.ajax({
                url: server.ip + url,
                async: sync ? false : true,
                data: JSON.stringify(data),
                beforeSend: function () {

                },
                complete: function () {
                    setTimeout(function () {
                    }, 1000);

                },
                success: function (r) {
                    if (!r.e.code) {
                        callback(r.data.sendData);
                    } else {
                        alert(r.e.desc);
                    }
                },
                error: function (e) {
                    alert(url + e.responseText);
                }
            });
        },
    });
</script>

<script type="text/javascript">
    var app = new Vue({
        el: "#app",
        data: {
            userId: getUrlParamObj().userId,
            dateTime: getUrlParamObj().dateTime,
            regionId: getUrlParamObj().departId ? getUrlParamObj().departId : '',
            firstVisitList: [],
            returnFlag: false,
            signInList: [],
            allPlanList: [],
        },
        methods: {
            show: function (item) {
                console.log(item)
                return false
            },
            isFair: function (item) {
                var str = '';
                if (!this.distanceJq(item.signInDistance) && !this.timeJq(item.signInTimeDiff)) {
                    str = "距离、时间不合理"
                } else if (!this.distanceJq(item.signInDistance)) {
                    str = "距离不合理"
                } else if (!this.timeJq(item.signInTimeDiff)) {
                    str = "时间不合理"
                }
                return str
            },
            //距离合理->true 不合理->false
            distanceJq: function (d) {
                var str = d.replace("公里", "");
                return Number(str) < 15
            },
            //时间合理->true 不合理->false
            timeJq: function (t) {
                if (t.indexOf("小时") > 0) {
                    var hour = t.split("小时")[0];
                    if (Number(hour) > 0) {
                        return false;
                    }
                } else {
                    if (t.indexOf("分") > 0) {
                        var min = t.split("分")[0];
                        if (Number(min) > 30) {
                            return false;
                        }
                    } else {
                        return true;
                    }
                }
                return true;
            },
            //距离间隔
            dJq: function (d) {
                var str = d.replace("公里", "");
                console.log("距离间隔 = " + str)
                if (str == '0') {
                    return '';
                } else {
                    return Number(str).toFixed(2);
                }
            },
            //速度
            disJq: function (dis) {
                var str = dis.replace("km/h", "");
                return str;
            },
            //去秒加0几分
            quMiao: function (m) {
                if (!m) return ""
                //1小时11分11秒
                var hour = "0"
                var min = "0"
                var sec = "0"

                if (m.indexOf("小时") > 0) {
                    //{1  , 11分11秒} 1小时55秒
                    hour = m.split("小时")[0]
                }
                if (m.indexOf("分") > 0) {
                    //{1小时11，11秒}
                    min = m.split("分")[0]
                    if (min.indexOf("小时") > 0) {
                        //{1,11}
                        min = min.split("小时")[1]
                    }
                    if (Number(min) < 10) {
                        min = "0" + min
                    }
                }
                if (min == "0" && m.indexOf("秒") > 0) {
                    //21秒
                    return hour + "小时01分"
                }
                return hour + "小时" + min + "分"
            },
            //添加0小时xx分
            addZeroHour: function (h) {
                if (!h) {
                    return ""
                }
                if (h.indexOf('小时') > 0) {
                    return h
                } else {
                    return "0小时" + h
                }
            },
            //打开基本信息
            lookInfo: function (userId) {
                var that = this
                var obj = {
                    type: 'customerList',
                    url: '/reportForm/personnel/entry.html?userId=' + userId,
                    name: '基本信息'
                }
                prompt(JSON.stringify(obj));
            },
            //查看下属
            lookDaQu: function (item) {
                var that = this
                var obj = {
                    type: 'customerList',
                    url: '/reportForm/newManager/managerFirstFaceDetailApp.html?userId=' + item.userId + '&dateTime=' + that.dateTime + '&departName=' + item.departName,
                    name: item.departName
                }
                prompt(JSON.stringify(obj));
            },
            //获取天气
            get_weather: function (item, i, lat, lng) {
                var that = this;
                $.wyui.postMethod(urlConfig.other.getTheWeather, {
                    "lat": lat,
                    "lng": lng
                }, function (data) {
                    var weather = data.weather[0];
                    var obj = {
                        'text_day': weather.text_day,
                        'low': weather.low,
                        'high': weather.high,
                        'code_day': weather.code_day
                    }
                    item.weather = obj
                });
            },
            get_date: function (list) {
                var data;
                var current = [];
                var last = [];
                var next = [];
                var benNian = new Date().Format("yyyy");
                var benYue = new Date().Format("M");
                var lastTime = '';
                var currentTime = new Date().Format("yyyy-MM");
                var today = new Date().Format("yyyy-MM-dd");
                var nextTime = '';
                if (Number(benYue) + 1 > 12) {
                    nextTime = Number(benNian) + 1 + "-01"
                } else if (Number(benYue) + 1 < 10) {
                    nextTime = Number(benNian) + "-0" + (Number(benYue) + 1)
                } else {
                    nextTime = Number(benNian) + "-" + (Number(benYue) + 1)
                }
                if (Number(benYue) - 1 < 1) {
                    lastTime = Number(benNian) - 1 + "-12"
                } else if (Number(benYue) - 1 < 10) {
                    lastTime = Number(benNian) + "-0" + (Number(benYue) - 1)
                } else {
                    lastTime = Number(benNian) + "-" + (Number(benYue) - 1)
                }
                for (var i = 0; i < list.length; i++) {
                    if (lastTime == list[i].leaveDate.substring(0, 7)) {
                        last.push({date: list[i].leaveDate, data: '假', yy: list[i].remark})
                    }
                    if (currentTime == list[i].leaveDate.substring(0, 7)) {
                        if (today == list[i].leaveDate) {
                            current.push({
                                date: list[i].leaveDate,
                                data: '假',
                                today: true,
                                yy: list[i].remark
                            })
                        } else {
                            current.push({date: list[i].leaveDate, data: '假', yy: list[i].remark})
                        }
                    }
                    if (nextTime == list[i].leaveDate.substring(0, 7)) {
                        next.push({date: list[i].leaveDate, data: '假', yy: list[i].remark})
                    }
                }
                data = {
                    last: last,
                    current: current,
                    next: next
                }
                console.log(data)
                return data

            },
            getCountDays: function (dateStr) {//返回当月的天数
                var curDate = new Date(dateStr);
                var curMonth = curDate.getMonth();
                curDate.setMonth(curMonth + 1);
                curDate.setDate(0);
                return curDate.getDate();
            },
            get_signIn: function (item, userId) {
                var that = this;
                $.wyui.postMethod(urlConfig.newZXQReportForm.getLeaveReasonByUserId, {
                    "userId": userId,
                }, function (data) {
                    var obj = {
                        'beginTime': '',
                        'endTime': '',
                        'remark': '',
                        'userId': ''
                    }
                    if (data.records && data.records.length > 0) {
                        obj = {
                            'beginTime': data.records[0].beginTime,
                            'endTime': data.records[0].endTime,
                            'remark': data.records[0].remark,
                            'userId': data.records[0].userId
                        }
                    }
                    item.leave = obj
                });
            },
            getFirstVisit: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.newZXQReportForm.getBRMTodayFirstVisitAndSignForZSQ, {
                    "userId": that.userId,
                    "dateTime": that.dateTime,
                    "regionId": that.regionId,
                }, function (data) {
                    for (var i = 0; i < data.records.length; i++) {
                        data.records[i].weather = {}
                        data.records[i].leave = {}
                    }
                    handlerData(data.records)
                    var obj = {
                        dialog: 'hidden'
                    }
                    prompt(JSON.stringify(obj))
                    for (var i = 0; i < that.allPlanList.length; i++) {
                        for (var j = 0; j < that.allPlanList[i].planList.length; j++) {
                            var item = that.allPlanList[i].planList[j]
                            if (item.signInLatitude) {
                                //有签到 获取天气
                                that.get_weather(item, i, item.signInLatitude, item.signInLongitude)
                            } else {
                                //没有签到,查询请假信息
                                that.get_signIn(item, item.userId)
                            }
                        }
                    }
                    console.log(that.allPlanList)
                    setTimeout(function () {  //使用  setTimeout（）方法设定定时2000毫秒
                        that.returnFlag = true;
                    }, 500);
                    var obj = {
                        dialog: 'hidden'
                    }
                    prompt(JSON.stringify(obj))
                });
            },
            setMessageReadFlag: function (receiverId) {
                $.wyui.postMethod(urlConfig.system.message.setMessageReadFlag, {
                    receiverId: receiverId,
                    flag: '1'
                }, function (data) {
                })
            },
            unique: function (arr, field) {
                var map = {};
                var res = [];
                for (var i = 0; i < arr.length; i++) {
                    if (!map[arr[i][field]]) {
                        map[arr[i][field]] = 1;
                        res.push(arr[i]);
                    }
                }
                return res;
            }
        },
        mounted: function () {
            var obj = {
                dialog: 'show'
            }
            prompt(JSON.stringify(obj))
            this.getFirstVisit()
            if (getUrlParamObj().msg == "0") {
                //从消息点进来的,标为已读
                this.setMessageReadFlag(getUrlParamObj().receiverId)
            }
        },
    })
</script>
<script>
    function handlerData(list) {
        //处理数据
        var zongjingliList = []
        var xiaoShouZongjian = []
        var zongjianList = []
        var daQuList = []
        var quYuList = []

        for (var i = 0; i < list.length; i++) {
            var plan = list[i]
            if (plan.roleName == '总经理') {
                zongjingliList.push(plan)
            } else if (plan.roleName == '销售总监') {
                xiaoShouZongjian.push(plan)
            } else if (plan.roleName == '区域总监') {
                zongjianList.push(plan)
            } else if (plan.roleName == '大区经理') {
                daQuList.push(plan)
            } else if (plan.roleName == '区域经理') {
                quYuList.push(plan)
            } else if (plan.roleName == '区域组长') {
                quYuList.push(plan)
            }
        }
        //总经理
//        if (zongjingliList.length > 0) {
//            var obj = {
//                title: '总经理',
//                planList: zongjingliList
//            }
//            app.allPlanList.push(obj)
//        }
        //销售总监
       if (xiaoShouZongjian.length > 0) {
           var obj = {
               title: '销售总监',
               planList: xiaoShouZongjian
           }
           app.allPlanList.push(obj)
       }
        //区域总监
        if (zongjianList.length > 0) {
            var obj = {
                title: '区域总监',
                planList: zongjianList
            }
            app.allPlanList.push(obj)
        }
        //大区经理
        if (daQuList.length > 0) {
            var obj = {
                title: '大区经理',
                planList: daQuList
            }
            app.allPlanList.push(obj)
            console.log(app.allPlanList)
        }
        //根据大区名字分开
        // var departList = app.unique(quYuList, 'departName')
        // //区域经理
        // for (var i = 0; i < departList.length; i++) {
        //     var list = []
        //     for (var j = 0; j < quYuList.length; j++) {
        //         if (quYuList[j].departName == departList[i].departName) {
        //             list.push(quYuList[j])
        //         }
        //     }
        //     var obj = {
        //         title: departList[i].departName,
        //         planList: list
        //     }
        //     app.allPlanList.push(obj)
        //
        // }
    }
</script>
<script>
    // 复杂的自定义覆盖物
    function ComplexCustomOverlay(point, text) {
        this._point = point;
        this._text = text;

    }

    ComplexCustomOverlay.prototype = new BMap.Overlay();
    ComplexCustomOverlay.prototype.initialize = function (map) {
        this._map = map;
        var div = this._div = document.createElement("div");
        div.style.position = "absolute";
        div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
        div.style.backgroundColor = "#fff";
        div.style.border = "1px solid #333";
        div.style.color = "#333";
        div.style.height = "22px";
        div.style.paddingLeft = "2px";
        div.style.paddingRight = "2px";
        div.style.lineHeight = "20px";
        div.style.whiteSpace = "nowrap";
        div.style.MozUserSelect = "none";
        div.style.fontSize = "12px"
        var span = this._span = document.createElement("span");
        div.appendChild(span);
        span.appendChild(document.createTextNode(this._text));
        var that = this;

        var arrow = this._arrow = document.createElement("div");
        arrow.style.background = "url(/dist/img/jiao2.png) no-repeat";
        arrow.style.position = "absolute";
        arrow.style.width = "11px";
        arrow.style.height = "10px";
        arrow.style.top = "19px";
        arrow.style.left = "10px";
        arrow.style.overflow = "hidden";
        div.appendChild(arrow);

        map.getPanes().labelPane.appendChild(div);

        return div;
    }
    ComplexCustomOverlay.prototype.draw = function () {
        var map = this._map;
        var pixel = map.pointToOverlayPixel(this._point);
        this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
        this._div.style.top = pixel.y - 65 + "px";
    }

    // 复杂的自定义覆盖物2
    function ComplexCustomOverlay2(point, text) {
        this._point = point;
        this._text = text;

    }

    ComplexCustomOverlay2.prototype = new BMap.Overlay();
    ComplexCustomOverlay2.prototype.initialize = function (map) {
        this._map = map;
        var div = this._div = document.createElement("div");
        div.style.position = "absolute";
        div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
        div.style.backgroundColor = "#fff";
        div.style.border = "1px solid #333";
        div.style.color = "#333";
        div.style.height = "22px";
        div.style.paddingLeft = "2px";
        div.style.paddingRight = "2px";
        div.style.lineHeight = "20px";
        div.style.whiteSpace = "nowrap";
        div.style.MozUserSelect = "none";
        div.style.fontSize = "12px"
        var span = this._span = document.createElement("span");
        div.appendChild(span);
        span.appendChild(document.createTextNode(this._text));
        var that = this;

        var arrow = this._arrow = document.createElement("div");
        arrow.style.background = "url(/dist/img/jiao2.png) no-repeat";
        arrow.style.position = "absolute";
        arrow.style.width = "11px";
        arrow.style.height = "10px";
        arrow.style.top = "19px";
        arrow.style.left = "10px";
        arrow.style.overflow = "hidden";
        div.appendChild(arrow);

        map.getPanes().labelPane.appendChild(div);

        return div;
    }
    ComplexCustomOverlay2.prototype.draw = function () {
        var map = this._map;
        var pixel = map.pointToOverlayPixel(this._point);
        this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
        this._div.style.top = pixel.y - 86 + "px";
    }
    Vue.directive('line-inserted', {
        inserted: function (el, binding) {
            var lineIndex = binding.value;
            showMap(lineIndex);
        }
    });

    //根据经纬度的距离获取地图的缩放级
    function getRoom(diff) {
        var room = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
        var diffArr = new Array(360, 180, 90, 45, 22, 11, 5, 2.5, 1.25, 0.6, 0.3, 0.15, 0.07, 0.03, 0);
        for (var i = 0; i < diffArr.length; i++) {
            if ((diff - diffArr[i]) >= 0) {
                return room[i];
            }
        }
        return 14;
    }

    //通过经纬度获取中心位置和缩放级别
    function getCenterPoint(maxJ, minJ, maxW, minW) {
        if (maxJ < minJ) {
            var minJ2 = maxJ
            maxJ = minJ
            minJ = minJ2
        }
        if (maxW < minW) {
            var minW2 = maxW
            maxW = minW
            minW = minW2
        }
        if (maxJ == minJ && maxW == minW) return [maxJ, maxW, 9];
        var diff = maxJ - minJ;
        if (diff < (maxW - minW)) diff = maxW - minW;
        diff = parseInt(10000 * diff) / 10000;
        var centerJ = minJ * 1000000 + 1000000 * (maxJ - minJ) / 2;
        var centerW = minW * 1000000 + 1000000 * (maxW - minW) / 2;
        var zoom = getRoom(diff);
        return [centerJ / 1000000, centerW / 1000000, zoom];
    }

    function showMap(lineIndex) {
        //console.log(lineIndex)
        var arr = lineIndex.split('-')
        var a0 = arr[0]
        var a1 = arr[1]
        // if (lineIndex.length = 2){
        //     a0 = lineIndex.substring(0, 1)
        //     a1 = lineIndex.substring(1, 2)
        // }else if (lineIndex.length>2) {
        //     a0 = lineIndex.substring(0, 2)
        //     a1 = lineIndex.substring(2, lineIndex.length)
        // }
        // console.log(a0 + ',' + a1)
        //console.log(app.allPlanList[a0].planList[a1])
        var signInLongitude = app.allPlanList[a0].planList[a1].signInLongitude
        var signInLatitude = app.allPlanList[a0].planList[a1].signInLatitude
        var arrivalsLongitude = app.allPlanList[a0].planList[a1].arrivalsLongitude
        var arrivalsLatitude = app.allPlanList[a0].planList[a1].arrivalsLatitude
        var signTime = app.allPlanList[a0].planList[a1].signTime
        var arrivalsTime = app.allPlanList[a0].planList[a1].arrivalsTime

        var userId = app.allPlanList[a0].planList[a1].userId


        var id = "map" + lineIndex
        //console.log(id)
        var map = new BMap.Map(id);
        map.disableDragging();
        if (signInLongitude && arrivalsLongitude) {
            var CenterPoint = getCenterPoint(signInLongitude, arrivalsLongitude, signInLatitude, arrivalsLatitude)
            var point = new BMap.Point(CenterPoint[0], CenterPoint[1]);
            map.centerAndZoom(point, CenterPoint[2] - 1);
            var p1 = new BMap.Point(signInLongitude, signInLatitude);
            var p2 = new BMap.Point(arrivalsLongitude, arrivalsLatitude);
            var chaJ = Math.abs(Number(signInLongitude) - Number(arrivalsLongitude))
            var chaW = Math.abs(Number(signInLatitude) - Number(arrivalsLatitude))
            // console.log(chaJ, chaW)
            var startIcon = new BMap.Icon("/dist/img/start.png", new BMap.Size(74, 106), {
                    imageOffset: new BMap.Size(0, -25)
                }
            );
            if (chaJ < 0.001 && chaW < 0.001) {
                var endIcon = new BMap.Icon("/dist/img/end.png", new BMap.Size(74, 106), {
                        imageOffset: new BMap.Size(10, -25)
                    }
                );
            } else {
                var endIcon = new BMap.Icon("/dist/img/end.png", new BMap.Size(74, 106), {
                        imageOffset: new BMap.Size(0, -25)
                    }
                );
            }
            var marker = new BMap.Marker(p1, {icon: startIcon});  // 创建标注
            marker.addEventListener("click", function () {
                //alert("签到");
                getSignInPic(userId)
            });
            var marker2 = new BMap.Marker(p2, {icon: endIcon});  // 创建标注
            marker2.addEventListener("click", function () {
                //alert("首面");
                getFirstVisitPic(userId)
            });
            map.addOverlay(marker);
            map.addOverlay(marker2);
            var myCompOverlay = new ComplexCustomOverlay(p1, "考勤签到 " + new Date(signTime).Format("hh:mm"));
            if (chaJ < 0.001 && chaW < 0.001) {
                var myCompOverlay2 = new ComplexCustomOverlay2(p2, "首次面访签到 " + new Date(arrivalsTime).Format("hh:mm"));
            } else {
                var myCompOverlay2 = new ComplexCustomOverlay(p2, "首次面访签到 " + new Date(arrivalsTime).Format("hh:mm"));

            }
//            map.addOverlay(myCompOverlay);
//            map.addOverlay(myCompOverlay2);

        } else if (signInLongitude) {
            console.log()
            var point = new BMap.Point(signInLongitude, signInLatitude);
            map.centerAndZoom(point, 13);
            var startIcon = new BMap.Icon("/dist/img/start.png", new BMap.Size(74, 106), {
                    imageOffset: new BMap.Size(0, -25)
                }
            );
            var marker2 = new BMap.Marker(point, {icon: startIcon});  // 创建标注
            marker2.addEventListener("click", function () {
                //alert("签到");
                getSignInPic(userId)
            });
            map.addOverlay(marker2);
            var myCompOverlay = new ComplexCustomOverlay(point, "考勤签到 " + new Date(signTime).Format("hh:mm"));
//            map.addOverlay(myCompOverlay);
        } else {
            var point = new BMap.Point(arrivalsLongitude, arrivalsLatitude);
            map.centerAndZoom(point, 13);
            var endIcon = new BMap.Icon("/dist/img/end.png", new BMap.Size(74, 106), {
                    imageOffset: new BMap.Size(0, -25)
                }
            );
            var marker2 = new BMap.Marker(point, {icon: endIcon});  // 创建标注
            marker2.addEventListener("click", function () {
                //alert("首面");
                getFirstVisitPic(userId)
            });
            map.addOverlay(marker2);
            var myCompOverlay = new ComplexCustomOverlay(point, "首次面访签到 " + new Date(arrivalsTime).Format("hh:mm"));
//            map.addOverlay(myCompOverlay);
        }

    }
</script>
<script>
    function getSignInPic(userId) {
        var obj = {
            dialog: 'show'
        }
        prompt(JSON.stringify(obj))
        var that = this;
        $.wyui.postMethod("/signIn/getSignInByDay.json", {
            userId: userId,
            signDate: new Date().Format("yyyy-MM-dd"),
        }, function (data) {
            var obj = {
                dialog: 'hidden'
            }
            prompt(JSON.stringify(obj))
            var url1 = data.signUrl
            var url2 = data.signOutUrl
            var urls = ""
            if (url1) {
                urls = url1
            }
            if (url2) {
                urls = url1 + ',' + url2
            }
            var obj = {
                type: 'img',
                imgList: urls,
                position: 0,
                item: JSON.stringify(data)
            }
            prompt(JSON.stringify(obj))
        });
    }

    function getFirstVisitPic(userId) {
        var obj = {
            dialog: 'show'
        }
        prompt(JSON.stringify(obj))
        var that = this;
        $.wyui.postMethod("/wreportCusVisit/getFirstVisit.json", {
            userId: userId,
            reportDate: new Date().Format("yyyy-MM-dd"),
            visitMode: "1"
        }, function (data) {
            var obj = {
                dialog: 'hidden'
            }
            prompt(JSON.stringify(obj))
            if (data && data.length > 0) {
                var first = data[0]
                console.log(first)

                var url1 = first.arrivalsImg
                var url2 = first.leaveImg
                var urls = ""
                if (url1) {
                    urls = url1
                }
                if (url2) {
                    urls = url1 + ',' + url2
                }
                var obj = {
                    type: 'img',
                    imgList: urls,
                    position: 0
                }
                prompt(JSON.stringify(obj))
            }
        });
    }

    var isDragEnable = true

    function setFaster() {
        if (isDragEnable) {
            //alert("Faster")
            map.disableDragging();
            map2.disableDragging();
        }
    }

    function setSlower() {
        //alert("slower")
        if (isDragEnable) {
            map.enableDragging();
            map2.enableDragging();
        }
    }


</script>

<script>
    Vue.directive('line-inserted2', {
        inserted: function (el, binding) {
            var lineIndex = binding.value;
            console.log(lineIndex);
            if (lineIndex && lineIndex.indexOf('-') > 0) {
                showCalendar(lineIndex);
            }
        }
    });

    function showCalendar(lineIndex) {
        var id = "#demo-box" + lineIndex
        var arr = lineIndex.split('-')
        var a0 = arr[0]
        var a1 = arr[1]
        console.log(app.allPlanList[a0].planList[a1])
        $.wyui.postMethod("/newAppReportForZSQ/getCalendar.json", {
            "userId": app.allPlanList[a0].planList[a1].userId,
            "dateTime": new Date().Format("yyyy-MM"),
        }, function (data) {
            var res = app.get_date(data)
            $(id).calendar({
                ele: id, //依附
                title: '',
                data: res
            });
        });

    }

</script>
</body>
</html>